/*
 *    Copyright © OpenAtom Foundation.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.inspur.edp.bef.dtgenerator.api.mgrInterface.method;

import com.inspur.edp.bef.bizentity.GspBizEntityObject;
import com.inspur.edp.bef.dtgenerator.DotNetToJavaStringHelper;
import com.inspur.edp.caf.generator.baseInfo.InterfaceMethodGenerateInfo;
import com.inspur.edp.caf.generator.baseInfo.ParameterInfo;
import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.method.InterfaceMethodGenerator;
import com.inspur.edp.caf.generator.method.InterfaceMethodGeneratorContext;
import java.util.ArrayList;
import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;

public class MgrInterfaceDeleteGenerator extends InterfaceMethodGenerator {

  // region BasicInfo
  private GspBizEntityObject node;

  public MgrInterfaceDeleteGenerator(GspBizEntityObject node) {
    this.node = node;
  }

  @Override
  protected InterfaceMethodGeneratorContext createClassInfoContext() {
    return new InterfaceMethodGeneratorContext();
  }

  @Override
  protected InterfaceMethodGenerateInfo createClassMethodInfo() {
    return new InterfaceMethodGenerateInfo();
  }

  @Override
  protected java.util.ArrayList<ModifierKeyword> getAccessModifiers() {
    return new java.util.ArrayList<ModifierKeyword>();
  }

  @Override
  protected String getMethodName() {
    if (node.getCode().equals("Child")) {
      return "delete" + "ChildNode";
    }
    return "delete" + node.getCode();
  }

  @Override
  protected java.util.ArrayList<ParameterInfo> getParameterCollection() {
    GspBizEntityObject node = this.node;
    java.util.Stack<String> stack = new java.util.Stack<String>();
    int paramCount = 0;

    while (node.getParentObject() != null) {
      paramCount++;
      node = node.getParentObject();
      stack.push(formatParameter(node.getCode()));
    }
    java.util.ArrayList<ParameterInfo> list = new java.util.ArrayList<ParameterInfo>();
    for (int i = 0; i < paramCount; i++) {
      ParameterInfo tempVar = new ParameterInfo();
      tempVar.setParamName(stack.pop() + "Id");
      tempVar.setParamType(com.inspur.edp.cef.generator.overall.Utils.createTypeInfo(String.class));
      list.add(tempVar);
    }
    ParameterInfo tempVar2 = new ParameterInfo();
    tempVar2.setParamName("ids");
    TypeInfo info = new TypeInfo(java.util.List.class);
    info.setIsParameterizedType(true);
    ArrayList<TypeInfo> listGenericTypes = new ArrayList<TypeInfo>();
    listGenericTypes.add(new TypeInfo(String.class));
    info.setArguments(listGenericTypes);
    tempVar2.setParamType(info);
    list.add(tempVar2);

    return list;
  }

  private String formatParameter(String source) {
    if (!DotNetToJavaStringHelper.isNullOrEmpty(source)) {
      if (source.length() > 1) {
        return Character.toLowerCase(source.charAt(0)) + source.substring(1);
      }
      return new String(new char[] {Character.toLowerCase(source.charAt(0))});
    }
    return null;
  }

  @Override
  protected TypeInfo getReturnType() {
    return new TypeInfo("void");
  }
  // endregion
}
